package group

import (
	"context"

	"gitee.com/gao-deguang/easy-chat/apps/social/api/internal/svc"
	"gitee.com/gao-deguang/easy-chat/apps/social/api/internal/types"
	"gitee.com/gao-deguang/easy-chat/apps/social/rpc/social"
	"gitee.com/gao-deguang/easy-chat/pkg/ctxdata"

	"github.com/zeromicro/go-zero/core/logx"
)

type GroupPutInLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 入群申请
func NewGroupPutInLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GroupPutInLogic {
	return &GroupPutInLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GroupPutInLogic) GroupPutIn(req *types.GroupPutInReq) (resp *types.GroupPutInResp, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.Social.GroupPutIn(l.ctx, &social.GroupPutInReq{
		GroupId:    req.GroupId,
		UserId:     ctxdata.GetUID(l.ctx),
		ReqMsg:     req.ReqMsg,
		ReqTime:    req.ReqTime,
		JoinSource: int32(req.JoinSource),
	})

	//todo:入群成功后创建会话
	//申请的时候看看自己是否入群了(需要在添加对应的返回值)
	//是否创建了会话，若没有，则创建
	//调用IMRPC服务
	return
}
